<template>
  <view class="login-page-container">
	<!-- 背景装饰 -->
	    <view class="background-decor">
	      <view class="circle circle-1"></view>
	      <view class="circle circle-2"></view>
	      <view class="circle circle-3"></view>
	      <view class="wave wave-1"></view>
	      <view class="wave wave-2"></view>
	    </view>  
	  
    <!-- 背景装饰 -->
    <view class="background-decor">
      <view class="circle circle-1"></view>
      <view class="circle circle-2"></view>
      <view class="circle circle-3"></view>
      <view class="wave wave-1"></view>
      <view class="wave wave-2"></view>
    </view>
    
    <!-- 企业信息展示区域 -->
    <view class="enterprise-section">
      <view class="logo-container">
        <image class="enterprise-logo" src="/static/enterprise-logo.png" mode="aspectFit"></image>
      </view>
      <view class="enterprise-info">
        <text class="enterprise-name">{{ enterpriseInfo.name }}</text>
        <text class="enterprise-subtitle">{{ enterpriseInfo.subtitle }}</text>
        <text class="enterprise-desc">{{ enterpriseInfo.description }}</text>
      </view>
    </view>
    
    <!-- 登录表单 -->
    <view class="login-card">
      <view class="login-header">
        <text class="login-title">用户登录</text>
        <text class="login-subtitle">欢迎使用能源管理系统</text>
      </view>
      
      <view class="form-container">
        <view class="input-group">
          <view class="input-item">
            <view class="input-label">
              <text class="label-text">用户名</text>
              <text class="label-required">*</text>
            </view>
            <view class="input-wrapper">
              <text class="input-icon">👤</text>
              <input 
                class="input-field" 
                v-model="username" 
                placeholder="请输入用户名/手机号"
                placeholder-class="input-placeholder"
                maxlength="20"
              />
              <text class="input-clear" v-if="username" @tap="username = ''">×</text>
            </view>
          </view>
          
          <view class="input-item">
            <view class="input-label">
              <text class="label-text">密码</text>
              <text class="label-required">*</text>
            </view>
            <view class="input-wrapper">
              <text class="input-icon">🔒</text>
              <input 
                class="input-field" 
                v-model="password" 
                password 
                placeholder="请输入密码"
                placeholder-class="input-placeholder"
                maxlength="20"
                @confirm="handleLogin"
              />
              <text class="input-clear" v-if="password" @tap="password = ''">×</text>
            </view>
          </view>
        </view>
        
        <view class="login-options">
          <label class="remember-me">
            <checkbox-group @change="onRememberChange">
              <label class="checkbox-wrapper">
                <checkbox value="remember" :checked="remember" color="#1890ff" />
                <text class="checkbox-text">记住密码</text>
              </label>
            </checkbox-group>
          </label>
          <text class="forgot-password" @tap="showForgotPassword">忘记密码?</text>
        </view>
        
        <button class="login-btn" :class="{ 'login-btn-disabled': !canLogin }" :disabled="!canLogin" @tap="handleLogin">
          <text class="login-btn-text">{{ loginLoading ? '登录中...' : '登录' }}</text>
        </button>
        
        <view class="register-tip">
          <text>还没有账号? </text>
          <text class="register-link" @tap="goToRegister">立即注册</text>
        </view>
      </view>
    </view>
    
    <!-- 系统特性展示 -->
    <view class="features-section">
      <view class="features-title">
        <text class="features-title-text">系统特性</text>
      </view>
      <view class="features-grid">
        <view class="feature-item">
          <view class="feature-icon">⚡</view>
          <text class="feature-text">实时监控</text>
        </view>
        <view class="feature-item">
          <view class="feature-icon">📊</view>
          <text class="feature-text">数据分析</text>
        </view>
        <view class="feature-item">
          <view class="feature-icon">💰</view>
          <text class="feature-text">费用管理</text>
        </view>
        <view class="feature-item">
          <view class="feature-icon">🔔</view>
          <text class="feature-text">智能提醒</text>
        </view>
      </view>
    </view>
    
    <!-- 版权信息 -->
    <view class="copyright-section">
      <text class="copyright-text">© 2025 {{ enterpriseInfo.shortName }} 版权所有</text>
      <text class="version-text">版本号: {{ appVersion }}</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: 'demo',
      password: '123456',
      remember: false,
      loginLoading: false,
      
      enterpriseInfo: {
        name: '深圳市起风智能科技有限公司',
        shortName: '深圳市起风智能科技有限公司',
        //subtitle: '企业智能电表管理系统',
        description: '专业电力监控与管理解决方案'
      },
      
      appVersion: 'V2.1.0'
    }
  },
  
  computed: {
    canLogin() {
      return this.username.length > 0 && this.password.length > 0 && !this.loginLoading;
    }
  },
  
  methods: {
    onRememberChange(e) {
      this.remember = e.detail.value.length > 0;
    },
    
    handleLogin() {
      if (!this.canLogin) return;
      
      // 简单的表单验证
      if (this.username.length < 3) {
        uni.showToast({
          title: '用户名至少3位字符',
          icon: 'none'
        })
        return
      }
      
      if (this.password.length < 6) {
        uni.showToast({
          title: '密码至少6位字符',
          icon: 'none'
        })
        return
      }
      
      // 模拟登录过程
      this.loginLoading = true;
      
      uni.showLoading({
        title: '登录中...',
        mask: true
      })
      
      setTimeout(() => {
        uni.hideLoading()
        this.loginLoading = false;
        
        // 模拟登录成功
        if (this.username === 'demo' && this.password === '123456') {
          // 存储登录状态
          uni.setStorageSync('isLogin', true)
          uni.setStorageSync('userInfo', {
            username: this.username,
            name: '演示用户',
            phone: '138****5678',
            remember: this.remember
          })
          
          // 存储企业信息
          uni.setStorageSync('enterpriseInfo', this.enterpriseInfo)
          
          uni.showToast({
            title: '登录成功',
            icon: 'success',
            duration: 1500,
            success: () => {
              // 跳转到主页
              setTimeout(() => {
                uni.switchTab({
                  url: '/pages/index/index'
                })
              }, 1500)
            }
          })
        } else {
          uni.showToast({
            title: '用户名或密码错误',
            icon: 'none'
          })
        }
      }, 2000)
    },
    
    showForgotPassword() {
      uni.showModal({
        title: '忘记密码',
        content: '请联系系统管理员重置密码\n联系电话: 400-123-4567',
        showCancel: false,
        confirmText: '知道了'
      })
    },
    
    goToRegister() {
      uni.showModal({
        title: '账号注册',
        content: '请联系系统管理员创建账号\n联系电话: 400-123-4567',
        showCancel: false,
        confirmText: '知道了'
      })
    }
  },
  
  onLoad() {
    // 检查是否有记住的登录信息
    const userInfo = uni.getStorageSync('userInfo')
    if (userInfo && userInfo.remember) {
      this.username = userInfo.username
      this.remember = true
    }
    
    // 加载企业信息
    const savedEnterpriseInfo = uni.getStorageSync('enterpriseInfo')
    if (savedEnterpriseInfo) {
      this.enterpriseInfo = { ...this.enterpriseInfo, ...savedEnterpriseInfo }
    }
  },
  
  onReady() {
    // 页面加载完成后的动画效果
    setTimeout(() => {
      //this.animateElements();
    }, 300);
  },
  
  animateElements() {
        // 这里可以添加一些简单的动画效果
        // 实际项目中可以使用 CSS 动画或动画库
      }
}
</script>

<style scoped>
/* 修改容器样式 */
.login-page-container {
  height: 100vh;
  height: 100%;
  background: linear-gradient(135deg, #1a2980 0%, #26d0ce 100%);
  overflow: auto;
  position: relative;
}

/* 其他样式保持不变 */
.background-decor {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
}

.circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
}

.circle-1 {
  width: 200rpx;
  height: 200rpx;
  top: 10%;
  left: 10%;
  animation: float 6s ease-in-out infinite;
}

.circle-2 {
  width: 300rpx;
  height: 300rpx;
  bottom: 15%;
  right: 10%;
  animation: float 8s ease-in-out infinite;
}

.circle-3 {
  width: 150rpx;
  height: 150rpx;
  top: 50%;
  left: 5%;
  animation: float 7s ease-in-out infinite;
}

.wave {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100rpx;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 50% 50% 0 0;
}

.wave-1 {
  bottom: 0;
  animation: wave 10s linear infinite;
}

.wave-2 {
  bottom: 20rpx;
  height: 80rpx;
  opacity: 0.7;
  animation: wave 8s linear infinite reverse;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20rpx); }
}

@keyframes wave {
  0% { transform: translateX(0); }
  50% { transform: translateX(-50rpx); }
  100% { transform: translateX(0); }
}

/* 企业信息区域 */
.enterprise-section {
  padding: 50rpx 50rpx 40rpx;
  text-align: center;
  z-index: 10;
  position: relative;
}

.logo-container {
  margin-bottom: 30rpx;
}

.enterprise-logo {
  width: 120rpx;
  height: 120rpx;
  border-radius: 24rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.2);
}

.enterprise-info {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.enterprise-name {
  font-size: 36rpx;
  font-weight: 700;
  color: white;
  margin-bottom: 16rpx;
  line-height: 1.4;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 100rpx;
}

.enterprise-subtitle {
  font-size: 32rpx;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 12rpx;
  font-weight: 500;
}

.enterprise-desc {
  font-size: 26rpx;
  color: rgba(255, 255, 255, 0.7);
}

/* 登录表单 */
.login-card {
  background: white;
  border-radius: 32rpx 32rpx 0 0;
  padding: 30rpx 50rpx;
  margin-top: auto;
  box-shadow: 0 -10rpx 40rpx rgba(0, 0, 0, 0.1);
  z-index: 20;
  position: relative;
}

.login-header {
  text-align: center;
  margin-bottom: 60rpx;
}

.login-title {
  display: block;
  font-size: 48rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 16rpx;
}

.login-subtitle {
  font-size: 28rpx;
  color: #666;
}

.input-group {
  margin-bottom: 40rpx;
}

.input-item {
  margin-bottom: 40rpx;
}

.input-label {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}

.label-text {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.label-required {
  color: #ff4d4f;
  margin-left: 8rpx;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: #f8f9fa;
  border-radius: 16rpx;
  padding: 0 24rpx;
  border: 2rpx solid #e8e8e8;
  transition: all 0.3s;
}

.input-wrapper:focus-within {
  border-color: #1890ff;
  background: white;
  box-shadow: 0 0 0 4rpx rgba(24, 144, 255, 0.1);
}

.input-icon {
  font-size: 32rpx;
  margin-right: 20rpx;
  color: #999;
}

.input-field {
  flex: 1;
  height: 88rpx;
  font-size: 28rpx;
  color: #333;
}

.input-placeholder {
  color: #ccc;
  font-size: 28rpx;
}

.input-clear {
  position: absolute;
  right: 24rpx;
  font-size: 36rpx;
  color: #ccc;
  width: 40rpx;
  height: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-clear:active {
  color: #999;
}

.login-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 60rpx;
}

.remember-me {
  display: flex;
  align-items: center;
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
}

.checkbox-text {
  font-size: 26rpx;
  color: #666;
  margin-left: 12rpx;
}

.forgot-password {
  font-size: 26rpx;
  color: #1890ff;
}

.login-btn {
  background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  color: white;
  height: 96rpx;
  border-radius: 16rpx;
  font-size: 32rpx;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 40rpx;
  width: 100%;
  border: none;
  box-shadow: 0 8rpx 24rpx rgba(24, 144, 255, 0.3);
  transition: all 0.3s;
}

.login-btn:active {
  transform: translateY(2rpx);
  box-shadow: 0 4rpx 12rpx rgba(24, 144, 255, 0.3);
}

.login-btn-disabled {
  background: #f5f5f5;
  color: #ccc;
  box-shadow: none;
}

.login-btn-disabled:active {
  transform: none;
  box-shadow: none;
}

.login-btn-text {
  font-size: 32rpx;
  font-weight: 500;
}

.register-tip {
  text-align: center;
  font-size: 26rpx;
  color: #666;
}

.register-link {
  color: #1890ff;
  font-weight: 500;
}

/* 系统特性展示 */
.features-section {
  padding: 40rpx 50rpx;
  background: white;
  z-index: 10;
  position: relative;
}

.features-title {
  text-align: center;
  margin-bottom: 40rpx;
}

.features-title-text {
  font-size: 28rpx;
  color: #666;
  font-weight: 500;
}

.features-grid {
  display: flex;
  justify-content: space-around;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.feature-icon {
  width: 80rpx;
  height: 80rpx;
  border-radius: 50%;
  background: #f0f8ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36rpx;
  margin-bottom: 16rpx;
}

.feature-text {
  font-size: 24rpx;
  color: #666;
}

/* 版权信息 */
.copyright-section {
  padding: 30rpx 50rpx 20rpx;
  text-align: center;
  z-index: 10;
  position: relative;
  background: transparent;
}

.copyright-text {
  display: block;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 12rpx;
}

.version-text {
  display: block;
  font-size: 22rpx;
  color: rgba(255, 255, 255, 0.5);
}
</style>